package com.tim.wicket.examples.converter;

import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Locale;

import org.apache.wicket.util.convert.converter.AbstractNumberConverter;

public class CurrencyConverter extends AbstractNumberConverter<Number> {

	private static final long serialVersionUID = 1L;

	public Number convertToObject(String value, Locale locale) {
		try {
			return NumberFormat.getCurrencyInstance(locale).parse(value);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		return null;
	}

	@Override
	public NumberFormat getNumberFormat(Locale locale) {
		return NumberFormat.getCurrencyInstance(locale);
	}

	@Override
	protected Class getTargetType() {
		return Double.class;
	}

}
